package com.cmict.data.system.service.oa;

import com.cmict.data.framework.common.pojo.PageResult;
import com.cmict.data.framework.common.util.date.DateUtils;
import com.cmict.data.system.api.user.AdminUserApiImpl;
import com.cmict.data.system.controller.admin.oa.vo.*;
import com.cmict.data.system.convert.oa.ScheduleManagementConvert;
import com.cmict.data.system.dal.dataobject.oa.ScheduleManagementDO;
import com.cmict.data.system.dal.mysql.oa.ScheduleManagementMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 日程管理 Service 实现类
 * @author
 */
@Service("scheduleManagementService")
@Slf4j
public class ScheduleManagementServiceImpl implements ScheduleManagementService{

    @Resource
    private ScheduleManagementMapper scheduleManagementMapper;

    @Resource
    private AdminUserApiImpl adminUserApiImpl;


    @Override
    public Long createScheduleManagement(ScheduleManagementCreateReqVO reqVO) {
        ScheduleManagementDO scheduleManagement = ScheduleManagementConvert.INSTANCE.convert(reqVO);
        scheduleManagementMapper.insert(scheduleManagement);
        return scheduleManagement.getId();
    }

    @Override
    public void updateScheduleManagement(ScheduleManagementUpdateReqVO reqVO) {
        ScheduleManagementDO scheduleManagement = ScheduleManagementConvert.INSTANCE.convert(reqVO);
        scheduleManagementMapper.updateById(scheduleManagement);
    }

    @Override
    public void deleteScheduleManagement(Long id) {
        scheduleManagementMapper.deleteById(id);
    }

    @Override
    public List<ScheduleManagementDO> getScheduleManagementList(ScheduleManagementCalendarReqVO reqVO) {
        return scheduleManagementMapper.selectList(reqVO);
    }

    @Override
    public PageResult<ScheduleManagementDO> getScheduleManagementPage(ScheduleManagementPageReqVO reqVO) {
        return scheduleManagementMapper.selectPage(reqVO);
    }

    @Override
    public List<ScheduleManagementDO> selectListNoPush(ScheduleManagementNoPushReqVO reqVO) {
        return scheduleManagementMapper.selectListNoPush(reqVO);
    }

    @Override
    public void updateLaterRemind(Long id) {
        ScheduleManagementUpdateReqVO reqVO = new ScheduleManagementUpdateReqVO();
        reqVO.setId(id);
        reqVO.setSendTime(DateUtils.of(new Date(new Date().getTime()+300000)));
        ScheduleManagementDO scheduleManagement = ScheduleManagementConvert.INSTANCE.convert(reqVO);
        scheduleManagementMapper.updateById(scheduleManagement);
    }

}
